using System;
using System.Collections.Generic;
using System.Text;

namespace PersistenceObject.Framework
{
    public class ObjectMapContainer
    {
        private ObjectMapContainer()
        {
            this.list = new Dictionary<Type, ObjectMap>();
        }
        public static readonly ObjectMapContainer Instance = new ObjectMapContainer();

        private object LockObject = new object();

        private Dictionary<Type, ObjectMap> list;
        public Dictionary<Type, ObjectMap> List
        {
            get { return list; }
        }

        public ObjectMap Get(Type type)
        {
            if (this.list.ContainsKey(type))
            {
                return this.list[type];
            }
            else
            {
                return AddObjectMap(type);
            }
        }

        private ObjectMap AddObjectMap(Type type)
        {
            lock (this.LockObject)
            {
                if (!this.list.ContainsKey(type))
                {
                    ObjectMap om = new ObjectMap(type);
                    this.list.Add(type, om);
                    return om;
                }
                else
                {
                    return this.list[type];
                }
            }
        }
    }
}
